<?php
namespace app\api\controller\v1;
use app\api\logic\QuanLogic;
use think\Db;
use think\Log;
use app\service\TechnService;
use app\service\TechnWeixinService;
use think\Request;

class Techn extends Base
{
	public function _initialize()
	{
		parent::_initialize();
	}

	/**
	 * 技师申请(初审提交)
	 */
	public function apply_step1()
	{
		$this->IsLogin(); //验证登录
		$result['code'] = -1;
		$result['msg'] = "非法请求";
		$params = $this->data_post;
		$params['user'] = $this->user;
		//dump($params);
		$validate = $this->validate(
			$params,
			[
				'real_name' => 'require',
				'sex' => 'require',
				'age' => 'require|integer|egt:0',
				'work_year' => 'require|integer|egt:0',
				'mobile' => ['require', 'regex' => '^1((3|4|5|6|7|8|9){1}\d{1})\d{8}$'],
				'county' => 'require'
			],
			[
				'real_name.require' => '请输入真实姓名',
				'sex.require' => '请选择性别',
				'age.require' => '请输入年龄',
				'age.integer' => '年龄只能为整数',
				'age.egt' => '年龄只能大于等于0',
				'work_year.require' => '请输入从业年份',
				'work_year.integer' => '从业年份只能为整数',
				'work_year.egt' => '从业年份只能大于等于0',
				'mobile.require' => '请输入手机号',
				'mobile.regex' => '手机格式有误',
				'county.require' => '请选择意向工作城市'
			]
		);
		if(true !== $validate)
		{
			echo json_encode(['code' => -1, 'msg' => $validate]);
			exit();
		}
        //判断是否上传个人生活照
        if(count($params['self_img_arr']) <= 0)
        {
        	echo json_encode(['code' => -1, 'msg' => '请上传个人生活照']);
			exit();
        }
        //判断是否已成为技师
        $techn_info = Db::name('techn')->where('user_id=:user_id')->bind(['user_id' => $params['user']['id']])->find();
        if(!empty($techn_info))
        {
        	echo json_encode(['code' => -1, 'msg' => '已是技师无需申请']);
			exit();
        }
        //判断是否有申请信息
        //判断是添加还是修改查询条件
        $techn_apply_map = '';
        $techn_apply_bind = [];
        if(empty($params['id']))
        {
        	//添加
        	$techn_apply_map = 'user_id=:user_id AND type=:type AND status IN (:status) AND is_delete_time=:is_delete_time';
        	$techn_apply_bind = ['user_id' => $params['user']['id'], 'type' => 1, 'status' => '0,1,2', 'is_delete_time' => 0];
        }else
        {
        	//修改
        	$techn_apply_map = 'user_id=:user_id AND type=:type AND status IN (:status) AND is_delete_time=:is_delete_time AND id<>:id';
        	$techn_apply_bind = ['user_id' => $params['user']['id'], 'type' => 1, 'status' => '0,1,2', 'is_delete_time' => 0, 'id' => $params['id']];
        }
        $techn_apply_info = Db::name('techn_apply')->where($techn_apply_map)->bind($techn_apply_bind)->find();
        if(!empty($techn_apply_info))
        {
        	echo json_encode(['code' => -1, 'msg' => '用户已存在申请信息']);
			exit();
        }
        //查询选择地区是否开启
        //判断是添加还是更新
        //基础数据
        $data = [
        	'real_name' => $params['real_name'],
        	'sex' => $params['sex'],
        	'age' => $params['age'],
        	'work_year' => $params['work_year'],
        	'mobile' => $params['mobile'],
        	'province' => $params['province'],
        	'city' => $params['city'],
        	'county' => $params['county'],
        	'province_name' => Db::name('area')->where(['id' => $params['province']])->value('name'),
        	'city_name' => Db::name('area')->where(['id' => $params['city']])->value('name'),
        	'county_name' => Db::name('area')->where(['id' => $params['county']])->value('name'),
        	'self_img' => implode(",", $params['self_img_arr']),
        	'type' => 1,
        	'steps' => TechnService::$type_apply_array[1]['steps'],
        	'no_step' => 1
        ];
        if(empty($params['id']))
        {
        	//添加
	        //写入主表
	        $data['user_id'] = $params['user']['id'];
	        $data['add_time'] = time();
        	$data['upd_time'] = time();
	        //启动事务
	        Db::startTrans();
	        $techn_apply_id = Db::name('techn_apply')->insertGetId($data);
	        if($techn_apply_id <= 0)
	        {
	        	//回滚事务
	        	Db::rollback();
	        	echo json_encode(['code' => -1, 'msg' => '申请失败']);
				exit();
	        }
	        //写入附表
	        $techn_audit_id = Db::name('techn_audit')->insertGetId([
	        	'techn_apply_id' => $techn_apply_id,
	        	'no_step' => 1,
	        	'apply_time' => time(),
	        	'add_time' => time(),
	        	'upd_time' => time()
	        ]);
	        if($techn_audit_id <= 0)
	        {
	        	//回滚事务
	        	Db::rollback();
	        	echo json_encode(['code' => -1, 'msg' => '申请失败']);
				exit();
	        }
	        //提交事务
	        Db::commit();
	        echo json_encode(['code' => 0, 'msg' => '申请成功，等待管理员审核']);
			exit();
	    }else
	    {
	    	//修改
	    	$data['upd_time'] = time();
	    	//查询主表信息
	    	$up_info = Db::name('techn_apply')->where(['id' => $params['id'], 'user_id' => $params['user']['id'], 'is_delete_time' => 0])->find();
	    	if(empty($up_info))
	    	{
	    		echo json_encode(['code' => -1, 'msg' => '审核信息不存在']);
				exit();
	    	}
	    	if($up_info['no_step'] != 1)
	    	{
	    		echo json_encode(['code' => -1, 'msg' => '禁止修改']);
				exit();
	    	}
	    	if($up_info['status'] != 0)
	    	{
	    		echo json_encode(['code' => -1, 'msg' => '禁止修改']);
				exit();
	    	}
	    	if(Db::name('techn_apply')->where(['id'=>$up_info['id']])->update($data))
	    	{
	    		echo json_encode(['code' => 0, 'msg' => '申请成功，等待管理员审核']);
				exit();
	    	}else
	    	{
	    		echo json_encode(['code' => -1, 'msg' => '申请失败']);
				exit();
	    	}
	    }
        echo json_encode($result);
	}

	/**
	 * 获取技师审核信息
	 */
	public function audit_info()
	{
		$this->IsLogin(); //验证登录
		$result['code'] = -1;
		$result['msg'] = "非法请求";
		$params = $this->data_post;
		$params['user'] = $this->user;
		//dump($params);
		//查询技师申请信息
		$info = Db::name('techn_apply')->where(['user_id' => $params['user']['id'], 'type' => 1, 'is_delete_time' => 0])->order('id desc')->find();
		if(!empty($info))
		{
			$info['self_img_arr'] = !empty($info['self_img']) ? explode(",", $info['self_img']) : [];
			//获取审核状态
			$info['techn_audit'] = Db::name('techn_audit')->where(['techn_apply_id' => $info['id']])->column('no_step,status');
			//获取技师端小程序跳转路径
			$url = 'https://api.weixin.qq.com/wxa/generatescheme?access_token='.TechnWeixinService::get_mini_access_token();
			$mini_data = [
				'jump_wxa' => [
					'path' => 'pages/my/my',
					'env_version' => 'release'
				]
			];
			$mini_res = http_curl($url,json_encode($mini_data));
			$mini_res = json_decode($mini_res,true);
			if($mini_res['errcode'] == 0)
			{
				$info['openlink'] = $mini_res['openlink'];
			}
			$result['code'] = 0;
			$result['msg'] = '请求成功';
			$result['data'] = $info;
		}else
		{
			$result['code'] = -1;
			$result['msg'] = '暂无数据';
		}
		echo json_encode($result);
	}

	/**
	 * 获取技师列表
	 */
	public function lists(Request $request)
	{
		$result['code'] = -1;
		$result['msg'] = "非法请求";
		$params = $this->data_post;
        $params = $request->param();
        $params['page'] = isset($params['page']) ? $params['page'] : 1;
        $params['lat'] = 37.82475;
        $params['lng'] = 112.56158;

//        这是要注释的
//
//        if ($this->user['id'] == 6205){
//            $params['page'] = isset($params['page']) ? $params['page'] : 1;
//            $params['lat'] = 37.82475;
//            $params['lng'] = 112.56158;
////            临汾
////            $params['lat'] = 36.10741;
////            $params['lng'] = 111.47353;
////            $this->user['id'] = 6879;
////            $params['lat'] = 36.22459;
////            $params['lng'] = 113.12037;
//        }


		//表单验证
		$validate = $this->validate(
			$params,
			[
				'city' => 'require',
				'lng' => 'require',
				'lat' => 'require',
				'page' => 'require'
			],
			[
				'city.require' => '请选择城市',
				'lng.require' => '坐标信息有误',
				'lat.require' => '坐标信息有误',
				'page.require' => '分页有误'
			]
		);

		if(true !== $validate)
        {
            echo json_encode(['code' => -1, 'msg' => $validate]);
            exit();
        }

//        log::write($params);
//        如果该城市有县级列表,去掉该市的县
        $is_city = Db::name('proxy')->where('shi',$params['city'])->find();
        if(!empty($is_city)){
            $qu = Db::name('proxy')->where('shi',$params['city'])->where('is_xian',1)->column('qu');
            if(!empty($qu)){
                $map = [
                    'T.city' => $params['city'],
                    'T.county' => ['not in',$qu],
                    'T.work_status' => ['in', '1,2']
                ];
            }else{
                $map = [
                    'T.city' => $params['city'],
                    'T.work_status' => ['in', '1,2']
                ];
            }
        }else{
            $map = [
                'T.county'=>$params['city'],
                'T.work_status' => ['in', '1,2'],

            ];
        }



        if(!empty($params['nickname']))
		{
			$map['T.nickname'] = ['like','%'.$params['nickname'].'%'];
		}

		if(!empty($params['class_id'])){
		    $map['T.service_class_id']=$params['class_id'];
		}
        if ($params['class_id'] == 0){
            $map['T.service_class_id']=0;
        }
		$orderdec='asc';
		if(!empty($params['dis'])){
		    if($params['dis']==2){
		        $orderdec='desc';
		    }
		}

		if(!empty($params['work_status'])){
		        $techn_ids=Db::name('order')->where(['status'=>['in','0,1,2,3,4,5'],'order_model'=>0])->column('techn_id');
		        $map['work_status']=1;
		    if($params['work_status']==1){//可预约
		        $map['T.id']=['in',$techn_ids];
		    }else{
		        $map['T.id']=['not in',$techn_ids];
		    }
		}

        $user = $this->user;
        if (!empty($user)){
            $not = Db::name('user')->where('id',$user['id'])->value('not_show');

            $techn_list = Db::name('techn')->where('not_show','like','%'.$user['id'].'%')->column('id');
            if (!empty($techn_list)){
                if (!empty($not)){
                    $not .= ',';
                }
                $not .= implode(',',$techn_list);
            }
            if (!empty($not)){
                $map['T.id'] = ['not in',$not];
            }

        }

// 		$map['work_status']=1;
		$field_lat = 'TL.lat';
		$field_lng = 'TL.lng';
		$lat = $params['lat'];
		$lng = $params['lng'];

		$list_data = Db::name('techn')
		             ->alias('T')
		             ->join('__TECHN_LAST__ TL', 'T.id = TL.techn_id', 'LEFT')
		             ->field("T.*, (6378.138 * 2 * asin(sqrt(pow(sin(({$field_lat} * pi() / 180 - {$lat} * pi() / 180) / 2),2) + cos({$field_lat} * pi() / 180) * cos({$lat} * pi() / 180) * pow(sin(({$field_lng} * pi() / 180 - {$lng} * pi() / 180) / 2),2))) * 1000) as distance")
		             ;
// 		if(!empty($params['work_status'])){
// 		    if($params['work_status']==1){//可预约
// 		        $list_data=$list_data->join('order o','o.techn_id=T.id and o.status not in (0,1,2,3,4,5) and o.order_model=0');
// 		    }else{
// 		        $list_data=$list_data->join('order o','o.techn_id=T.id and o.status in (0,1,2,3,4,5) and o.order_model=0');
// 		    }
// 		},(select  beiy  from jx_order where T.id=jx_order.techn_id and order_model=0 and status in(0,1,2,3,4,5) limit 1) as work_count
		$list_data=$list_data->where($map)->order('work_status asc,pre_time_y asc, distance '.$orderdec)
		             ->limit(($params['page']-1)*10,10);


// 		$sql=$list_data->fetchsql(true)->select();echo $sql;exit;

		$list_data=$list_data->select();
        if (empty($list_data)  && !empty($map['T.city'])){
            $map['T.county'] = $map['T.city'];
            unset($map['T.city']);
            $list_datas = Db::name('techn')
                ->alias('T')
                ->join('__TECHN_LAST__ TL', 'T.id = TL.techn_id', 'LEFT')
                ->field("T.*, (6378.138 * 2 * asin(sqrt(pow(sin(({$field_lat} * pi() / 180 - {$lat} * pi() / 180) / 2),2) + cos({$field_lat} * pi() / 180) * cos({$lat} * pi() / 180) * pow(sin(({$field_lng} * pi() / 180 - {$lng} * pi() / 180) / 2),2))) * 1000) as distance")
            ;
            $list_datas=$list_datas->where($map)->order('work_status asc,pre_time_y asc, distance '.$orderdec)
                ->limit(($params['page']-1)*10,01);
            $list_data=$list_datas->select();

        }

		if(!empty($list_data))
		{
			//遍历处理
			foreach($list_data as $key => $value)
			{

                //获取技师等级图标 收藏数  评论数
                $level = Db::name('techn_last')->where('techn_id',$value['id'])->find();
                $level_info = Db::name('techn_level')->where('id',$level['level_id'])->find();
                if (!empty($level_info))
                    $level_url = '/static/'.$level_info['rank'].'x.png';
                else
                    $level_url = '';

                $list_data[$key]['level_url'] = $level_url;
                $list_data[$key]['descs'] = strip_tags($list_data[$key]['descs']);

//                $list_data[$key]['collect_num'] = rand(20,80);
//                是新人
                if (time() - $value['add_time'] < 259200){
                    $list_data[$key]['is_new'] = 1;
                }else{
                    $list_data[$key]['is_new'] = 0;
                }
                //是销冠
                $guan = Db::name('techn_last')->order('total_result desc')->where('city',$params['city'])->where('techn_id','<>','299')->limit(0,3)->column('techn_id');
                if (!empty($guan) && in_array($value['id'],$guan)){
                    $list_data[$key]['is_guan'] = 1;
                }else{
                    $list_data[$key]['is_guan'] = 0;
                }
                $quan = Db::name('order')->where('techn_id',$value['id'])->where('add_time','>',(time()-259200))->where('jztype',1)->where('status',6)->find();
                if (!empty($quan)){
                    $list_data[$key]['is_guan'] = 1;
                }

                //是热门
                $hot = Db::name('techn_last')->order('total_result desc')->where('city',$params['city'])->where('techn_id','<>','299')->limit(4,10)->column('techn_id');
                if (!empty($hot) && in_array($value['id'],$hot)){
                    $list_data[$key]['is_hot'] = 1;
                }else{
                    $list_data[$key]['is_hot'] = 0;
                }
                $talk_num = Db::name('talk')->where('techn_id',$value['id'])->where('delete_time',0)->count('id');
                $all_xing = Db::name('talk')->where('techn_id',$value['id'])->where('delete_time',0)->sum('service_level');
                if (!empty($all_xing) && !empty($talk_num)){
                    $xing = round($all_xing/$talk_num,1);
                }else{
                    $xing = '4.'.rand(8,9);
                }
                $list_data[$key]['xing'] = $xing;

                if (isset($this->user['id'])){
                    $collect_list = Db::name('user')->where('id',$this->user['id'])->value('collect_techn');
                    $collect_list_arr = json_decode($collect_list,true);
                    if (!empty($collect_list_arr) && in_array($value['id'],$collect_list_arr)){
                        $list_data[$key]['collect_status'] = 1;
                    }else{
                        $list_data[$key]['collect_status'] = 0;
                    }
                }else{
                    $list_data[$key]['collect_status'] = 0;
                }
                $list_data[$key]['talk_num'] = Db::name('talk')->where('techn_id',$value['id'])->where('delete_time',0)->column('count(id)')[0];



				//处理工作形象照片
				$list_data[$key]['work_img'] = request()->domain().$value['work_img'];
				//处理个人生活照片
		        $self_img_array = explode(",", $value['self_img']);
		        foreach($self_img_array as $si_key => $si_value)
		        {
		        	$self_img_array[$si_key] = request()->domain().$si_value;
		        }
		        $list_data[$key]['self_img_array'] = $self_img_array;

				//处理技师工作状态
				$new_work_status = 0;
				$new_work_status_name = '';
				// if($value['work_status'] == 1)
				// {
				// 	//查询技师是否有下在进行中的订单
				// 	$run_order_info = Db::name('order')->where(['techn_id' => $value['id'], 'status' => ['in', '0,1,2,3,4,5'], 'order_model' => 0])->find();
				// 	if(empty($run_order_info))
				// 	{
				// 		$new_work_status = 1;
				// 		$new_work_status_name = '可服务';
				// 	}else
				// 	{
				// 		$new_work_status = 2;
				// 		$new_work_status_name = '可预约';
				// 	}
				// }elseif($value['work_status'] == 2)
				// {
				// 	$new_work_status = 3;
				// 	$new_work_status_name = '休息中';
				// }

				if(!empty($value['pre_time_y'])){
    				if($value['pre_time_y']-time()>2700){
    				    $new_work_status = 2;
    					$new_work_status_name = '可预约';
    				}else{
    				    $new_work_status = 1;
    					$new_work_status_name = '可服务';
    				}
				}else{
				    $new_work_status = 3;
					$new_work_status_name = '休息中';
				}
				$list_data[$key]['new_work_status'] = $new_work_status;
				$list_data[$key]['new_work_status_name'] = $new_work_status_name;
				$list_data[$key]['distance2'] = $value['distance'];
				//距离
				$int_distance = PriceNumberFormat($value['distance']/1000);
				$list_data[$key]['distance'] = $int_distance.'km';
				//判断是否可以预约
				$list_data[$key]['is_pre'] = $int_distance > 50 ? false : true;
				//技师最早可预约时间
				$pre_time = '';
				 $techn_pre_time = TechnService::TechnPreTime(['techn_id' => $value['id']]);
				 if(!empty($techn_pre_time))
				 {
				 	$pre_time_array = array_merge_recursive($techn_pre_time[0]['time_slot'], $techn_pre_time[1]['time_slot'], $techn_pre_time[2]['time_slot']);
				 	if(!empty($pre_time_array))
				 	{
				 		$pre_time = $pre_time_array[0]['time'];
				 	}
				 }

				$daymsg='后天 ';


				if(!empty($value['pre_time_y'])){
				    if(date('d',$value['pre_time_y'])==date('d')){
    				    $daymsg='今天 ';
    				}else if(date('d',$value['pre_time_y'])==date('d',time()+86400)){
    				    $daymsg='明天 ';
    				}
				    $list_data[$key]['pre_time'] = $daymsg.date('H:i',$value['pre_time_y']);
				}else{
				    $list_data[$key]['pre_time'] = '';
				}

                //评价列表
                $talk_list = Db::name('talk')->where('techn_id',$value['id'])->order('add_time desc')->where('delete_time',0)->select();
                $talk_titles = Db::name('talk_title')->where('is_delete_time',0)->column('talk_title','id');
                if (!empty($talk_list)){
                    foreach ($talk_list as $kk => $vv){
                        $talk_list[$kk]['add_time'] = date('m-d',$vv['add_time']);
                        $vv['title_ids'] = json_decode($vv['title_ids']);
                        foreach ($vv['title_ids'] as $vvv){
                            $talk_list[$kk]['titles'][] = $talk_titles[$vvv];
                        }

                    }
                }
                $list_data[$key]['talk_list'] = $talk_list;
			}

            //获取优惠券
//            $params['user'] = $this->user;



			$result['code'] = 0;
			$result['msg'] = '请求成功';

//            如果用户选择城市不发券,自动加载的发券
            if (empty($params['chang_city'])){
                if (!empty($this->user) && $params['page'] <= 1){
                    $user = $this->user;
                    $give_quan = QuanLogic::give_quan($user['id'],$params['city']);
                    if ($give_quan['code'] == 0){
                        $result['give_quan'] = 1;
                    }else{
                        $result['give_quan'] = 0;
                    }
                    $result['msg'] = $give_quan['msg'];
                }
            }

	        $result['data'] = $list_data;
	       // $result['sql']=Db::name('techn')
		          //   ->alias('T')
		          //   ->join('__TECHN_LAST__ TL', 'T.id = TL.techn_id', 'LEFT')
		          //   ->field("T.*, (6378.138 * 2 * asin(sqrt(pow(sin(({$field_lat} * pi() / 180 - {$lat} * pi() / 180) / 2),2) + cos({$field_lat} * pi() / 180) * cos({$lat} * pi() / 180) * pow(sin(({$field_lng} * pi() / 180 - {$lng} * pi() / 180) / 2),2))) * 1000) as distance,(select  beiy  from jx_order where T.id=jx_order.techn_id and order_model=0 and status in(0,1,2,3,4,5) limit 1) as work_count")->where($map)->order('work_count asc,pre_time_y asc, distance '.$orderdec)->fetchsql(true)->select()
		          //   ;

	        $result['service_class']=db::name('service_class')->where('is_delete_time',0)->select();

		}else
		{
            if ($params['page'] > 1){
                $result['msg'] = "到底了，下单吧！";
            }else{
                $result['msg'] = "即将上线!";
            }
			$result['code'] = -1;
		}

		echo json_encode($result,256);
	}

	/**
	 * 获取技师所服务的项目列表
	 */
	public function service_lis()
	{
		$result['code'] = -1;
		$result['msg'] = "非法请求";
		$params = $this->data_post;
		$validate = $this->validate(
			$params,
			[
				'techn_id' => 'require'
			],
			[
				'techn_id.require' => '技师信息有误'
			]
		);
		if(true !== $validate)
        {
            echo json_encode(['code' => -1, 'msg' => $validate]);
            exit();
        }
//        $nowser = Db::name('order_detail')->where('order_id',$params['order_id'])->value('service_id');
//        $smoney = Db::name('service')->where('id',$nowser)->value('price');

        //查询技师所服务的项目id
        $service_ids = Db::name('techn')->where(['id' => $params['techn_id']])->value('service_ids');

        if(empty($service_ids))
        {
        	echo json_encode(['code' => -1, 'msg' => '暂无服务项目']);
            exit();
        }
        $service_ids_arr = explode(",", trim($service_ids, ","));
        $map = [
        	'id' => ['in', $service_ids_arr],
        	'is_shelves' => 1,
        	'is_delete_time' => 0
        ];
//        $list_data = Db::name('service')->where($map)->where('price','>=',$smoney)->order('sort asc')->select();
        $list_data = Db::name('service')->where($map)->order('sort asc')->select();
        if(!empty($list_data))
        {
        	//遍历处理
        	foreach($list_data as $key => $value)
        	{
        		//图片
        		$list_data[$key]['images'] = request()->domain().$value['images'];
        		//价格美化
        		$list_data[$key]['price'] = PriceBeautify($value['price']);
        		$list_data[$key]['original_price'] = PriceBeautify($value['original_price']);
//        		$list_data[$key]['cha_price'] = round($value['price'] - $smoney,2);
//        		$list_data[$key]['smoney'] = $smoney;

        	}
        	$result['code'] = 0;
	        $result['msg'] = "请求成功";
	        $result['data'] = $list_data;
        }else
        {
        	$result['code'] = -1;
	        $result['msg'] = "暂无数据";
        }
        echo json_encode($result);
	}

	/**
	 * 技师详情
	 */
	public function detail()
	{
		$result['code'] = -1;
		$result['msg'] = "非法请求";
		$params = $this->data_post;
		//dump($params);
		$validate = $this->validate(
			$params,
			[
				'techn_id' => 'require'
			],
			[
				'techn_id.require' => '技师信息有误'
			]
		);
		if(true !== $validate)
        {
            echo json_encode(['code' => -1, 'msg' => $validate]);
            exit();
        }
        //查询技师信息
        $info = Db::name('techn')->where(['id' => $params['techn_id']])->find();
        if(empty($info))
        {
        	echo json_encode(['code' => -1, 'msg' => '技师不存在']);
            exit();
        }
        //处理工作形象照
        $info['work_img'] = request()->domain().$info['work_img'];
        //处理资格证书
        $diploma_img_array = explode(",", $info['diploma_img']);
        foreach($diploma_img_array as $key => $value)
        {
        	$diploma_img_array[$key] = request()->domain().$value;
        }
        $info['diploma_img_array'] = $diploma_img_array;
        //处理生活照
        $self_img_array = explode(",", $info['self_img']);
        foreach($self_img_array as $key => $value)
        {
        	$self_img_array[$key] = request()->domain().$value;
        }
        $info['self_img_array'] = $self_img_array;
        
        $info['descs']=strip_tags($info['descs']);
         
        $result['code'] = 0;
	    $result['msg'] = "请求成功";
	    $result['data'] = $info;

        echo json_encode($result);
	}
    public function collect(Request $request){
//        $this->IsLogin(); //验证登录
        $user = $this->user;
        $user['id'] = 6205;
        $status = $request->param();
        $userinfo = Db::name('user')->where('id',$user['id'])->find();
        $like = json_decode($userinfo['collect_techn'],true);
        if (!empty($like) && in_array($status['data']['id'],$like)){
            $key = array_search($status['data']['id'],$like);
            unset($like[$key]);
            $return['msg'] = '取消收藏成功';
            $return['code'] = 0;
            $collect_num = Db::name('techn')->where('id',$status['data']['id'])->value('collect_num') - 1;

        }else{
            $like[] = $status['data']['id'];
            $return['msg'] = '收藏成功';
            $return['code'] = 1;
            $collect_num = Db::name('techn')->where('id',$status['data']['id'])->value('collect_num') + 1;
        }
        $json = json_encode($like);
        $update = ['collect_techn'=>$json];
        $result = Db::name('user')->where('id',$user['id'])->update($update);
        $re = Db::name('techn')->where('id',$status['data']['id'])->update(['collect_num'=>$collect_num]);
        if ($result && $re){

        }else{
            $return = [
                'code'=>-1,
                'msg'=>'系统繁忙,请重试',
                'data'=>$status
            ];
        }
        return json_encode($return,256);
    }
}